package cloud.maque.sso.client.controller;

import cloud.maque.common.captcha.conf.CaptchaProperties;
import cloud.maque.common.captcha.dto.CaptchaDto;
import cloud.maque.common.captcha.service.CaptchaService;
import cloud.maque.common.core.response.R;
import cn.dev33.satoken.SaManager;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@ApiSupport(order = 10000)
@Tag(name = "验证码接口")
@RestController
public class CaptchaController {


    @Autowired
    CaptchaProperties captchaProperties;

    @Autowired
    CaptchaService captchaService;

    @Operation(summary = "获取验证码")
    @GetMapping("/captcha")
    public R<CaptchaDto> captcha() {
        CaptchaDto captcha = captchaService.getCaptcha();
        SaManager.getSaTokenDao().set("captcha:" + captcha.getId(), captcha.getCode(), captchaProperties.getExpire());

        //隐藏关键信息
        captcha.setCode("");
        return R.ok("生成验证码", captcha);
    }

}
